﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TouchRC.Classes;
using System.IO;
using TouchRC.Logging;
using Fluid.Controls;
using TouchRC.Custom_Controls;

namespace TouchRC.Logic
{
    public class VmcControllerRemote// : TelnetClient
    {
        public VmcControllerRemote(ComputerListBoxItem compy)
            // : base(compy.DnsAddress, compy.RemotePort)
        {
            AsynchronousClient.Init(compy);
        }

        public void ChangeVolume(RemoteCommands.VolumeOptions command)
        {
            AsynchronousClient.OpenAndSendRequest(RemoteCommands.ResolveVolumeCommand(command));
        }

        public void PressButton(RemoteCommands.ButtonCommands command)
        {
            AsynchronousClient.OpenAndSendRequest(RemoteCommands.ResolveButtonCommand(command));
        }

        public void GoToScreen(RemoteCommands.GoToPlaces command)
        {
            AsynchronousClient.OpenAndSendRequest(RemoteCommands.ResolveGoToCommand(command));
        }

        public void JumpToTime(TimeSpan time)
        {
            AsynchronousClient.OpenAndSendRequest("position " + time.TotalSeconds.ToString());
        }

        public VmcCMetaData GetCurrentlyPlayingMetaData()
        {
            string result = AsynchronousClient.OpenAndSendRequest("mediametadata");
            VmcCMetaData retval = ListenerLogic.ParseMetaDataValue(result);

            return retval;
        }

        public void SendFilesToQueue(params FileInfo[] files)
        {
            if (files.Length == 1)
            {
                AsynchronousClient.OpenAndSendRequest("play-video " + files[0].FullName);
            }
            else if (files.Length > 1)
            {
                Alert.Show("Only the first file will play.");
                SendFilesToQueue(files[0]);
            }
            else if (files.Length == 0)
            {
                Alert.Show("Could not find any associated files.");
            }
            else
            {
                Logger.LogMessage("Invalid file count. SendFilesToQueue(), file count: {0}", files.Length);
            }
        }
    }
}
